package com.shop.front.dao.sms;

import com.shop.domain.sms.SmsCode;
import com.shop.jpa.BaseDao;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface SmsCodeDao extends BaseDao<SmsCode, Long> {

    @Query("select count(*) from SmsCode where mobile = ?1 and createTime >= concat(?2,' 00:00:00') and createTime <= concat(?2,' 23:59:59')")
    int countByMobileAndDate(String mobile, String todayStr);

    @Query("select count(*) from SmsCode where ip = ?1 and createTime >= concat(?2,' 00:00:00') and createTime <= concat(?2,' 23:59:59')")
    int countByIpAndDate(String ip, String todayStr);

    /**
     * 通过手机号统计发送记录数
     *
     * 注意：此处通过 mobile 关联 user 表，只是为了测试 sharding-sphere 分表关联功能
     *
     * @param mobile
     * @param todayStr
     * @return
     */
    @Deprecated
    @Query("select count(*) from SmsCode s left join User u on s.mobile = u.mobile where s.mobile = ?1 and s.createTime >= concat(?2,' 00:00:00') and s.createTime <= concat(?2,' 23:59:59')")
    int countByUserMobileAndDate(String mobile, String todayStr);

}
